﻿namespace EasyWeb.Web.UI
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Linq.Expressions;
    using System.Text;
    using System.Threading.Tasks;
    using System.Web.Mvc;

    public class EWGridSortingBuilder<TModel>
    {
        public EWGridSortingBuilder(EWGrid<TModel> grid)
        {
            EWGuard.IsNotNull(grid, "grid");
            this.Component = grid;
        }

        public EWGrid<TModel> Component { get; private set; }

        public EWGridSortingBuilder<TModel> Default(string value)
        {
            this.Component.DefaultSort = value;
            return this;
        }

        public EWGridSortingBuilder<TModel> Default<TValue>(Expression<Func<TModel, TValue>> value)
        {
            this.Component.DefaultSort = value == null ? null : ExpressionHelper.GetExpressionText(value);
            return this;
        }

        public EWGridSortingBuilder<TModel> FieldName(string value)
        {
            this.Component.SortFieldName = value;
            return this;
        }

        public EWGridSortingBuilder<TModel> DirectionFieldName(string value)
        {
            this.Component.SortDirectionFieldName = value;
            return this;
        }
    }
}
